//
//  YSHomeProdListCell.m
//  Yueshi
//
//  Created by Northwan on 15/7/18.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSHomeProdListCell.h"

@interface YSHomeProdListCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *oldPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *discountLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *newsPriceLabel;
@end

@implementation YSHomeProdListCell

+(instancetype)initWithTableView:(UITableView *)tableView{
    static NSString *CellIdentiferId = @"YSHomeProdListCell";
    YSHomeProdListCell *cell =  [tableView dequeueReusableCellWithIdentifier:CellIdentiferId];
    if(cell == nil){
        NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"YSHomeProdListCell" owner:nil options:nil];
        cell = [nibs lastObject];
    }
    return cell;
}

-(void)setInfo:(YSProductList *)info{
    [self.nameLabel setText:info.prodWholeName];
    [self.iconView setImageURLStr:info.prodImageUrl];
    
    NSString *oldPrice = [NSString stringWithFormat:@"¥%.1f",info.prodOldPrice];
    [UIUtil addMiddleLineWithLabel:self.oldPriceLabel text:oldPrice];
    self.oldPriceLabel.hidden = YES;
    
    [self.newsPriceLabel setText:[NSString stringWithFormat:@"¥%.1f",info.prodNewPrice]];
    CGFloat discount =  info.prodNewPrice/info.prodOldPrice;
    if(info.prodPromotion && info.prodPromotion.price){
        discount = info.prodPromotion.price/info.prodOldPrice;
         [self.newsPriceLabel setText:[NSString stringWithFormat:@"¥%.1f",info.prodPromotion.price]];
    }
    [self.discountLabel setText:[NSString stringWithFormat:@"[%.1f折]",discount*10]];
   
    [self.buyCountLabel setText:[NSString stringWithFormat:@"已售%ld",info.prodBuyCount]];
}

@end
